<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /* div:target {
            background-color: #008c8c;
        } */

        :root {
            height: 100%;   
            /* 设置html元素的高度为视口的高度 */
        }
        body {
            margin: 0;
            height: 100%;
        }
        div.button-wrapper {
            position: absolute;
            width: 600px;
            top: 50%;
        }
        div.button-wrapper a{
            text-decoration: none;
            color: #fff;
            background-color: #fcc;
            font-size: 30px;
            border-radius: 3px;
            margin: 0 10px;
        }

        #red, #green, #gray {
            height: 100%;
        }
        #red {
            background-color: #f40;
        }
        #green {
            background-color: green;
        }
        #gray {
            background-color: gray;
        }
        div[id]:not(:target) {
            display: none;
        }
    </style>
</head>
<body>
    <!-- <a href="#box1">box1</a>
    <a href="#box2">box2</a>
    <div id="box1">box1</div> -->
    <!-- 根据url里面的hash值判断哪个div被选中 -->
    <!-- 可以利用css实现点击一个元素而改变另一个元素的样式 -->
    <!-- <div id="box2">box2</div> -->

    <div class="button-wrapper">
        <a href="#red" class="bgred">red</a>
        <a href="#green" class="bggreen">green</a>
        <a href="#gray" class="bggray">gray</a>
    </div>

    <div id="red"></div>
    <div id="green"></div>
    <div id="gray"></div>

</body>
</html>